package com.xidian.zhiancloud.controller.ypp.messageCenter.information;

import com.github.pagehelper.Page;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.Information;
import com.xidian.zhiancloud.model.syset.DepartList;
import com.xidian.zhiancloud.service.ypp.messageCenter.information.InformationService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * 消息
 *
 * 
 */
@RestController
@RequestMapping("/information")
public class InformationController {
    @Autowired
    private InformationService informationService;

//    @GetMapping("/getById/{status}")
//    public ResultDTO getById(
//            @PathVariable String status) {
//        return ResultDTO.successOf(informationService.getById(status), GeneralResponseEnums.SUCCESS);
//    }

    //批量修改状态 0表示未读，1表示已读
//    @PutMapping("/updateById")
//    public ResultDTO updateById(List<Information> informationList){
//        informationService.updateByIds(informationList);
//        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
//    }

    @GetMapping("/getInformationById")
    public ResultDTO getInformation(
            @RequestParam("id") Long id) {
        return ResultDTO.successOf(informationService.getInformation(id), GeneralResponseEnums.SUCCESS);
    }
    
    
    //添加
    @PostMapping("/add")
    public ResultDTO add(@RequestBody Information info)
    {
    	informationService.insertInfo(info);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
    
    
    //根据条件查询列表
    @GetMapping("/getList")
    public ResultDTO list(Information info)
    {
    	Page<Information> pagedata = informationService.getInformationList(info);
		
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("datalist", pagedata);
		data.put("PageNum", pagedata.getPageNum());
		data.put("PageSize", pagedata.getPageSize());
		data.put("PageTotal", pagedata.getPages());
		data.put("total", pagedata.getTotal());
		return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }
    
    //批量删除消息
    @GetMapping("/remove")
    public ResultDTO remove( @RequestParam("ids") Long[] ids)
    {
    	informationService.deleteInformationeByIds(ids);
    	return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
    
    //批量删除消息
    @GetMapping("/removeAll")
    public ResultDTO removeAll( )
    {
    	informationService.deleteInformationeAll();
    	return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
    
    //批量标记已读消息
    @GetMapping("/update")
    public ResultDTO update( @RequestParam("ids") Long[] ids)
    {
    	informationService.updateInformationByIds(ids);
    	return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

}
